package com.bookmanger.server.controller;

import com.bookmanger.common.result.Result;
import com.bookmanger.pojo.DTO.CheckInfoDTO;
import com.bookmanger.pojo.Entity.AdminEntity;
import com.bookmanger.pojo.Entity.Reader;
import com.bookmanger.server.service.SysAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys")
@Slf4j
public class SysAdminController {
    @Autowired
    private SysAdminService sysAdminService;
    @PostMapping("/admin/addAdmin")
    public Result addAdmin(@RequestBody AdminEntity adminEntity){
        return sysAdminService.addAdmin(adminEntity);
    }

    @PostMapping("/admin/deleteAdmin")
    public Result deleteAdmin(Integer id){
        return sysAdminService.deleteAdmin(id);
    }

    @PostMapping("/admin/update")
    public Result updateAdminInfo(@RequestBody AdminEntity adminEntity){
        return sysAdminService.updateAdminInfo(adminEntity);
    }

    @GetMapping("/admin/findAdminById")
    public Result findAdminById(Integer id){
        return sysAdminService.findAdminById(id);
    }

    @GetMapping("/admin/findAllAdmin")
    public Result findAllAdmin(){
        return sysAdminService.findAllAdmin();
    }

    // 分页查询所有管理员
    @GetMapping("/admin/findAllAdminByPage")
    public Result findAllAdminByPage(@RequestParam(defaultValue = "1") Integer page, 
                                    @RequestParam(defaultValue = "10") Integer pageSize){
        // 参数校验
        if (page <= 0) page = 1;
        if (pageSize <= 0 || pageSize > 100) pageSize = 10;
        
        return sysAdminService.findAllAdmin(page, pageSize);
    }

    //模糊搜索管理员
    @GetMapping("/admin/findAdminByInfo")
    public Result findAdminByInfo(String info){
        return sysAdminService.findAdminByInfo(info);
    }


    @GetMapping("/reader/findAllReader")
    public Result findAllReader(){
        return sysAdminService.findAllReader();
    }

    // 分页查询所有读者
    @GetMapping("/reader/findAllReaderByPage")
    public Result findAllReaderByPage(@RequestParam(defaultValue = "1") Integer page, 
                                     @RequestParam(defaultValue = "10") Integer pageSize){
        // 参数校验
        if (page <= 0) page = 1;
        if (pageSize <= 0 || pageSize > 100) pageSize = 10;
        
        return sysAdminService.findAllReader(page, pageSize);
    }

    @PostMapping("/reader/findReaderById")
    public Result findReaderById(Integer id){
        return sysAdminService.findReaderById(id);
    }

    @PostMapping("/reader/deleteReader")
    public Result deleteReader(Integer id){
        return sysAdminService.deleteReader(id);
    }

    @PostMapping("/reader/updateReaderInfoByAdmin")
    public Result updateReaderInfoByAdmin(@RequestBody Reader reader){
        return sysAdminService.updateReaderInfoByAdmin(reader);
    }

    @PostMapping("/reader/aggreeRegister")
    public Result aggreeRegister(Integer id, Integer type){
        return sysAdminService.aggreeRegister(id,type);
    }

    @PostMapping("/reader/disaggressRegister")
    public Result disaggressRegister(Integer id,String reason){
        return sysAdminService.disaggressRegister(id,reason);
    }
    @GetMapping("/reader/findReaderByInfo")
    public Result findReaderByInfo(String info){
        return sysAdminService.findReaderByInfo(info);
    }
}